import axios from 'axios';

// 报修服务API
/**
 * 获取报修服务列表
 * @param {object} params 查询参数
 */
export function getRepairList(params) {
    return axios.get('/api/services/repairs/', {
        params,
    });
}

/**
 * 获取报修服务详情
 * @param {number} id 报修ID
 * @returns
 */
export function getRepairDetail(id) {
    return axios.get(`/api/services/repairs/${id}/`);
}

/**
 * 指派维修工
 * @param {number} id 报修ID
 * @param {number} handlerUserId 维修工用户ID
 */
export function assignRepairHandler(id, handlerUserId) {
    return axios.put(`/api/services/repairs/${id}/`, {
        handler_user_id: handlerUserId,
    });
}

// 租赁申请服务API
/**
 * 获取租赁申请列表
 * @param {object} params 查询参数
 */
export function getLeasingApplicationList(params) {
    return axios.get('/api/services/leasing-applications/', { params });
}

/**
 * 获取租赁申请详情
 * @param {string} id 复合ID
 */
export function getLeasingApplicationDetail(id) {
    return axios.get(`/api/services/leasing-applications/${id}/`);
}

/**
 * 审批租赁申请
 * @param {string} id 复合ID
 * @param {object} data { status, approval_opinion }
 */
export function approveLeasingApplication(id, data) {
    return axios.put(`/api/services/leasing-applications/${id}/approve/`, data);
}

/**
 * 开始审批租赁申请
 * @param {string} id 复合ID
 */
export function startLeasingApplicationApproval(id) {
    return axios.put(`/api/services/leasing-applications/${id}/start-approval/`);
}

// 装修备案服务API
/**
 * 获取装修备案列表
 * @param {object} params 查询参数
 */
export function getDecorationApplicationList(params) {
    return axios.get('/api/services/decoration-applications/', { params });
}

/**
 * 获取装修备案详情
 * @param {number} id 申请ID
 */
export function getDecorationApplicationDetail(id) {
    return axios.get(`/api/services/decoration-applications/${id}/`);
}

/**
 * 审批装修备案
 * @param {number} id 申请ID
 * @param {object} data { status, approval_opinion }
 */
export function approveDecorationApplication(id, data) {
    return axios.put(`/api/services/decoration-applications/${id}/approve/`, data);
}

// 访客预约服务API
export function getVisitorAppointmentList(params) {
    return axios.get('/api/services/visitor-appointments/', { params });
}

export function getVisitorAppointmentById(id) {
    return axios.get(`/api/services/visitor-appointments/${id}/`);
}

export function createVisitorAppointment(data) {
    return axios.post('/api/services/visitor-appointments/', data);
}

export function updateVisitorAppointment(id, data) {
    return axios.put(`/api/services/visitor-appointments/${id}/`, data);
}

export function deleteVisitorAppointment(id) {
    return axios.delete(`/api/services/visitor-appointments/${id}/`);
}

// 送水服务API
/**
 * 获取送水服务列表
 * @param {object} params 查询参数, e.g., { status: '待受理' }
 */
export function getWaterDeliveryList(params) {
    return axios.get('/api/services/water-deliveries/', { params });
}

/**
 * 获取送水服务详情
 * @param {number} id 服务ID
 */
export function getWaterDeliveryDetail(id) {
    return axios.get(`/api/services/water-deliveries/${id}/`);
}

/**
 * 创建送水服务
 * @param {object} data 送水服务数据
 */
export function createWaterDelivery(data) {
    return axios.post('/api/services/water-deliveries/', data);
}

/**
 * 更新送水服务
 * @param {number} id 服务ID
 * @param {object} data 更新的数据
 */
export function updateWaterDelivery(id, data) {
    return axios.put(`/api/services/water-deliveries/${id}/`, data);
}

/**
 * 删除送水服务
 * @param {number} id 服务ID
 */
export function deleteWaterDelivery(id) {
    return axios.delete(`/api/services/water-deliveries/${id}/`);
}

/**
 * 批量删除送水服务
 * @param {Array} ids 服务ID数组
 */
export function batchDeleteWaterDelivery(ids) {
    return axios.post('/api/services/water-deliveries/batch-delete/', { ids });
}

/**
 * 更新送水服务状态
 * @param {number} id 服务ID
 * @param {number} status 状态码
 */
export function updateWaterDeliveryStatus(id, status) {
    return axios.put(`/api/services/water-deliveries/${id}/status/`, { status });
}

/**
 * 指派送水员
 * @param {number} id 服务ID
 * @param {number} delivererUserId 配送员用户ID
 */
export function assignWaterDeliverer(id, delivererUserId) {
    return axios.put(`/api/services/water-deliveries/${id}/`, {
        deliverer_user_id: delivererUserId,
    });
}

// 保洁服务API
/**
 * 获取保洁服务列表
 * @param {object} params 查询参数, e.g., { status: '待受理' }
 */
export function getCleaningBookingList(params) {
    return axios.get('/api/services/cleaning-bookings/', { params });
}

/**
 * 指派保洁员
 * @param {number} id 预约ID
 * @param {number} handlerUserId 保洁员用户ID
 */
export function assignCleaningHandler(id, handlerUserId) {
    return axios.put(`/api/services/cleaning-bookings/${id}/`, {
        handler_user_id: handlerUserId,
    });
}

// 临时停车服务API
/**
 * 获取停车记录列表
 * @param {object} params 
 */
export function getParkingRecords(params) {
    return axios.get('/api/services/temporary-parking/', { params });
}

/**
 * 创建停车记录 (车辆入场)
 * @param {object} data 
 */
export function createParkingRecord(data) {
    return axios.post('/api/services/temporary-parking/', data);
}

/**
 * 更新停车记录 (车辆出场/支付)
 * @param {number} id 
 * @param {object} data 
 */
export function updateParkingRecord(id, data) {
    return axios.put(`/api/services/temporary-parking/${id}/`, data);
}

/**
 * 根据车牌号获取车辆信息
 * @param {string} plateNumber 
 */
export function getVehicleByPlate(plateNumber) {
    return axios.get(`/api/services/vehicles/by-plate/${plateNumber}/`);
} 